// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import service from './service'
import { HappyScroll } from 'vue-happy-scroll'
import 'vue-happy-scroll/docs/happy-scroll.css'
import axios from 'axios'
import mysqlser from './mysqlser'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)
Vue.config.productionTip = false
Vue.prototype.service = service
Vue.prototype.mysqlser = mysqlser
Vue.prototype.$axios = axios
Vue.use(ElementUI);
Vue.component('happy-scroll', HappyScroll)

router.beforeEach((to, from, next) => {
  if(to.meta.requireAuto){
    if(localStorage.getItem('isLogin') == null){
      alert('您还未登录');
      next({
        path: '/',
      })
    }
    if(to.meta.level){
      if(localStorage.level === 'A'){
        next()
      }else{
        alert('权限不足');
        next({
          path: '/home'
        })
      }
    }
  }
  next()
})

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  render: h => h(App)
})
